package 斗地主游戏1控制台版;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class CodeUtil {
    static ArrayList<Character> Code = new ArrayList<>();

    public static String getCode() {
        Random r = new Random();
        String s = "";
        int Index = r.nextInt(10);
        String number = String.valueOf(Index);
        for (int i = 0; i < 26; i++) {
            char s1 = (char) (97 + i);
            char s2 = (char) (65 + i);
            Collections.addAll(Code, s1, s2);
        }

        Collections.shuffle(Code);
        for (int i = 0; i < 4; i++) {
            s = s + Code.get(i);
        }
        s = s + number;
        char[] charArray = s.toCharArray();
        int index = r.nextInt(charArray.length);
        char temp = charArray[4];
        charArray[4] = charArray[index];
        charArray[index] = temp;
        String code = new String(charArray);
        return code;
    }
}
